package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 讲师服务实现类
 * @author daygods
 * @since 2025-07-16
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Override
    public Page<EduTeacher> pageListCondition(long current, long limit, EduTeacher teacherQuery) {
        // 创建page对象
        Page<EduTeacher> pageParam = new Page<>(current, limit);
        
        // 构建条件
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        
        // 多条件组合查询
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String begin = teacherQuery.getGmtCreate();
        String end = teacherQuery.getGmtModified();
        
        // 判断条件值是否为空，如果不为空拼接条件
        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(level)) {
            wrapper.eq("level", level);
        }
        if (!StringUtils.isEmpty(begin)) {
            wrapper.ge("gmt_create", begin);
        }
        if (!StringUtils.isEmpty(end)) {
            wrapper.le("gmt_create", end);
        }
        
        // 排序
        wrapper.orderByDesc("gmt_create");
        
        // 调用方法实现条件查询分页
        baseMapper.selectPage(pageParam, wrapper);
        
        return pageParam;
    }
}